<template>
	<view class="refund-detail">
		<view class="head">
			<!-- status 0审核中 1待发货 2待收货 3已退款 -1已拒绝 -->
			<block v-if="type == -1">
				<view class="txt">{{i18n.RefundFailure}}</view>
				<view class="time">{{i18n.TimeApplication}}：{{detail.status_time}}</view>
			</block>
			<block v-if="type == 0">
				<view class="txt">{{i18n.UnderReview}}</view>
				<view class="time">{{i18n.TimeApplication}}：{{detail.status_time}}</view>
			</block>
			<block v-if="type == 1">
				<view class="txt">{{i18n.QTuihuo}}</view>
				<view class="time">{{i18n.TimeApplication}}：{{detail.status_time}}</view>
			</block>
			<block v-if="type == 2">
				<view class="txt">{{i18n.Qdendai}}</view>
				<view class="time">{{i18n.Remain}}：				
				<countDown :is-day="true" :tip-text="' '" :day-text="'天'" :hour-text="':'" :minute-text="':'" :second-text="' '"
				 :datatime="datatime"></countDown>
				</view>
			</block>
			<block v-if="type == 3">
				<view class="txt">{{i18n.RefundSuccessMoney}} ¥{{detail.refund_price}}</view>
				<view class="time">{{i18n.TimeApplication}}：{{detail.status_time}}</view>
			</block>
		</view>
		<!-- 拒绝 -->
		<view class="box" v-if="type == -1">
			<view class="txt">{{i18n.Jujue}}</view>
			<view class="des">{{detail.fail_message}}</view>
		</view>
		<!-- 待退货 -->
		<view class="info-box" v-if="type == 1">
			<view class="title">{{i18n.TongyiTuik}}</view>
			<view class="store-info">
				<view class="text">{{i18n.ConsigneeName}}：<text class="info">{{detail.mer_delivery_user}}</text></view>
				<view class="text">{{i18n.ConsigneeTel}}：<text class="info">{{detail.phone}}</text></view>
				<view class="text">{{i18n.ConsigneeAdd}}：<text class="des">{{detail.mer_delivery_address}}</text></view>
				<view class="red-txt">
					<text class="iconfont icon-zhuyi-copy"></text>{{i18n.Tuihui}}
				</view>
			</view>
		</view>
		<!-- 待收货 -->
		<view class="info-box" v-if="type == 2">
			<view class="title" style="color:#E93323">{{i18n.TuihuiMoney}}</view>
			<view class="store-info">
				<view class="text">{{i18n.ConsigneeName}}：<text class="info">{{detail.mer_delivery_user}}</text></view>
				<view class="text">{{i18n.ConsigneeTel}}：<text class="info">{{detail.phone}}</text></view>
				<view class="text">{{i18n.ConsigneeAdd}}：<text class="des">{{detail.mer_delivery_address}}</text></view>
			</view>
		</view>
		<view class="info-box">
			<view class="title">{{i18n.Tuikxx}}</view>
			<view class="product-box">
				<view class="product-item" v-for="(item,index) in detail.refundProduct" :key="index">
					<image class="img-box" :src="item.product.cart_info.productAttr.image" mode="" v-if="item.product.cart_info.productAttr.image"></image>
					<image class="img-box" :src="item.product.cart_info.product.image" mode="" v-else></image>
					<view class="msg">
						<view class="name line1"><text v-if="item.product.cart_info.product_type === 2" class="event_name event_bg">{{i18n.Presell}}</text>{{item.product.cart_info.product.store_name}}</view>
						<view class="des">{{item.product.cart_info.productAttr.sku}}</view>
						<view class="price">￥{{item.product.cart_info.productAttr.price}}</view>
						<view class="num">x {{item.refund_num}}</view>
					</view>
				</view>
			</view>
		</view>
		<view class="content">
			<view class="item">
				<view class="label">{{i18n.OrderID}}：</view>
				<view class="txt flex">
					<text>{{detail.refund_order_sn}}</text>
					<!-- #ifdef H5 -->
						<text class='copy copy-data' :data-clipboard-text="detail.refund_order_sn">复制</text>
					<!-- #endif -->
					<!-- #ifdef MP -->
						<text class='copy' @tap='copy'>{{i18n.Copy}}</text>
					<!-- #endif -->
				</view>
			</view>
			<view class="item">
				<view class="label">{{i18n.RefundMoney}}：</view>
				<view class="txt flex">
					<text>¥ {{detail.refund_price}}</text>
				</view>
			</view>
			<view class="item">
				<view class="label">{{i18n.ShenqSum}}：</view>
				<view class="txt flex">
					<text>{{detail.refund_num}}</text>
				</view>
			</view>
			<view class="item">
				<view class="label">{{i18n.TimeApplication}}：</view>
				<view class="txt flex">
					<text>{{detail.create_time}}</text>
				</view>
			</view>
			<view class="item">
				<view class="label">{{i18n.Beizhu}}：</view>
				<view class="txt flex">
					<text>{{detail.mark ? detail.mark : ""}}</text>
				</view>
			</view>
			<view class="btn-wrapper">
				<block v-if="type==-1">
					<view class="btn gray" @click="goService">{{i18n.LianxSj}}</view>
					<view class="btn" @click="applyAgain(detail)">{{i18n.ZaiciSq}}</view>
				</block>
				<block v-else-if="type==1">
					<view class="btn gray" @click="goService">{{i18n.LianxSj}}</view>
					<view class="btn" @click="goPage">{{i18n.TuihuiGoods}}</view>
				</block>
				<block v-else-if="type==2">
					<view class="btn gray" @click="goService">{{i18n.LianxSj}}</view>
					<view class="btn" @click="go">{{i18n.Chakwuliu}}</view>
				</block>
				<block v-else>
					<view class="btn" @click="goService">{{i18n.LianxSj}}</view>
				</block>
			</view>
		</view>
	</view>
</template>
<script>
	const globalData = getApp().globalData;
	import { refundDetail } from '@/api/order.js'
	import ClipboardJS from "@/plugin/clipboard/clipboard.js";
	import countDown from '@/components/countDown'
	export default{
		components: {
			countDown,	
		},
		data(){
			return{
				type:0,
				refund_order_id:0,
				detail:'',
				
				datatime: 0
			}
		},
		computed: {
			i18n() {
				return globalData.$t('refund_detail');
			},
		},
		onLoad(optios) {
			uni.setNavigationBarTitle({
			　　title:this.i18n.TuikDile
			})
			this.refund_order_id = optios.id
			this.getDetail()
		},
		onReady: function() {
			// #ifdef H5
			this.$nextTick(function() {				
				const clipboard = new ClipboardJS(".copy-data");
				clipboard.on("success", () => {
					this.$util.Tips({
						title: this.i18n.CopySuccess
					});
				});
			});
			// #endif
		},
		methods:{
			getDetail(){
				refundDetail(this.refund_order_id).then(res=>{
					// status 0审核中 1待发货 2待收货 3已退款 -1已拒绝 
					this.type = res.data.status
					this.detail = res.data
					this.datatime = res.data.auto_refund_time;
					
				})
			},
			goPage(){
				uni.navigateTo({
					url:'/pages/users/refund/goods/index?id='+this.detail.refund_order_id
				})
			},
			applyAgain(item){
				uni.navigateTo({
					url:`/pages/order_details/index?order_id=${item.refundProduct[0].product.order_id}`
				})
			},
			go(){
				uni.navigateTo({
					url:`/pages/users/refund/logistics?orderId=${this.detail.refund_order_id}`
				})
			},
			/**
			 * 
			 * 剪切订单号
			 */
			// #ifndef H5
			copy: function() {
				let that = this;
				uni.setClipboardData({
					data: this.detail.refund_order_sn
				});
			},
			// #endif
			// 客服
			goService(){
				uni.navigateTo({
					url:`/pages/chat/customer_list/chat?mer_id=${this.detail.mer_id}&uid=${this.detail.uid}&refund_order_id=${this.detail.refund_order_id}`
				})
			}
		}
	}
</script>

<style lang="scss">
.refund-detail{
	.head{
		display: flex;
		flex-direction: column;
		justify-content: center;
		height: 150rpx;
		padding: 0 30rpx;
		color: #fff;
		background-color: #666666;
		font-size: 30rpx;
		.txt{
			font-weight: bold;
		}
		.time{
			margin-top: 10rpx;
			font-size: 24rpx;
			opacity: .8;
			.time{
				display: inline-block;
				width: 600rpx;
				/deep/ .red{
					color: #fff;
				}
			}
		}
	}

	.info-box{
		margin-top: 12rpx;
		background-color: #fff;
		.title{
			padding: 0 32rpx;
			line-height: 86rpx;
			border-bottom: 1px solid #F0F0F0;
			color: #282828;
		}
		.product-box{
			.product-item{
				display: flex;
				padding: 25rpx 30rpx;
				.img-box{
					width:130rpx;
					height:130rpx;
					border-radius:16rpx;
				}
				.msg{
					position: relative;
					display: flex;
					flex-direction: column;
					justify-content: space-between;
					width: 440rpx;
					margin-left: 26rpx;
					.name{
						font-size: 28rpx;
						color: #282828;
					}
					.des{
						font-size: 20rpx;
						color: #868686;
					}
					.price{
						font-size: 26rpx;
						color: #E93323;
					}
					.num{
						position: absolute;
						right: -80rpx;
						top: 4rpx;
						color: #868686;
						font-size: 26rpx;
					}
				}
			}			
			.event_name{
				display: inline-block;
				margin-right: 9rpx;
				color: #fff;
				font-size: 20rpx;
				padding: 0 8rpx;
				line-height: 30rpx;	
				text-align: center;
				border-radius: 6rpx;						
			}
		}
		
		.event_bg{
			background: #FF7F00;
		}
		.store-info{
			padding: 30rpx;
			.des{
				margin-top: 10rpx;
				font-size: 26rpx;
				color: #868686;
			}
			.red-txt{
				display: flex;
				align-items: center;
				margin-top: 10rpx;
				color: #E93323;
				font-size: 24rpx;
				.iconfont{
					font-size: 30rpx;
					margin-right: 5rpx;
					margin-top: 6rpx;
				}
			}
		}
	}
	.content{
		margin-top: 12rpx;
		padding: 30rpx 30rpx 0;
		background-color: #FFFFFF;
		.item{
			display: flex;
			justify-content: space-between;
			margin-bottom: 30rpx;
			.txt{
				display: flex;
				flex-wrap: nowrap;
				justify-content: flex-end;
				align-items: center;
				width: 420rpx;
				color: #868686;
				text-align: right;
				.copy{
					display: flex;
					align-items: center;
					justify-content: center;
					width:76rpx;
					height:34rpx;
					margin-left: 20rpx;
					border:1px solid #666666;
					border-radius:17rpx;
					font-size: 20rpx;
					color: #333;
				}
			}
			&:last-child{
				margin-bottom: 0;
			}
		}	
		.btn-wrapper{
			position: relative;
			display: flex;
			justify-content: flex-end;
			align-items: center;
			height: 100rpx;
			button{
				font-size: 28rpx;
			}
			.btn{
				width:176rpx;
				height:60rpx;
				margin-left: 20rpx;
				line-height: 60rpx;
				background:#E93323;
				border-radius:30rpx;
				text-align: center;
				color: #fff;
			}
			.gray{
				background: transparent;
				border: 1px solid #eee;
				color: #AAAAAA;
			}
			&:after{
				content:' ';
				position: absolute;
				top: 0;
				left: 50%;
				width: 690rpx;
				height:1px;
				margin-left: -345rpx;
				background-color: #f0f0f0;
			}
		}
	}
	.box{
		margin-top: 12rpx;
		padding:25rpx 30rpx;
		background-color: #fff;
		font-size: 30rpx;
		color: #282828;
		.des{
			margin-top: 5rpx;
			font-size: 26rpx;
			color: #868686;
		}
	}
}
</style>
